<div class="row-fluid">
    <div id="dashboard-left" class="span8">
        <div id='schedule_appointments'></div>

        <br/>

    </div>
    <!--span8-->

    <div id="dashboard-right" class="span4 profile-left">

        <div class="widgetbox tags">
            <h4 class="widgettitle">Today Appointments List</h4>
            <div class="widgetcontent">
                <ul class="taglist">
                    <?php
                    foreach($today_appointments['data'] as $k => $arr){
                    ?>
                        <li><a href="javascript:void(0);"><?php echo '<strong>'.$arr['name'].'</strong> |  Call - '.$arr['telephone']; ?>&nbsp; <button class="btn btn-primary btn-small">Serviced</button><span class="close"></span></a></li>
                    <?php
                    }
                    ?>
                </ul>
                <!--<a href="#" style="display:block;margin-top:10px">+ Add Tag</a>-->
            </div>
        </div>

        <div class="widgetbox tags box-danger">
            <h4 class="widgettitle">Overdue Appointments List</h4>
            <div class="widgetcontent">
                <ul class="taglist">
                    <?php
                    foreach($overdue_appointments as $k => $arr){
                        $smaller_date =  date('Y-m-d');
                        $bigger_date = $arr['next_service_date'];
                        $sd_dt = $this->App->count_time_between_dates($smaller_date, $bigger_date,'days');
                        ?>
                        <li><a href="javascript:void(0);"><?php echo '<strong>'.$arr['name'].'</strong> |  Call - '.$arr['telephone']; ?>&nbsp; <button class="btn btn-danger btn-small"> <?php echo $sd_dt; ?> Day(s) to Service. Serviced </button><span class="close"></span></a></li>
                    <?php
                    }
                    ?>
                </ul>
                <!--<a href="#" style="display:block;margin-top:10px">+ Add Tag</a>-->
            </div>
        </div>

    </div>
<!--span4-->
</div><!--row-fluid-->
<script type="text/javascript">
    var appointments = <?php echo json_encode($appointments); ?>;
    var rlist = appointments['data'];
    //console.log(rlist);
    var event_data = [];
    for(var x in rlist){
        var dobj = rlist[x];
        var date = new Date(dobj['next_service_date']);
        var d = date.getDate();
        var m = date.getMonth();
        var y = date.getFullYear();
        var lbl = ' Service Appointment';
        if(dobj['serviced']== 'Serviced'){
            var cl = '#333';//default
        }
        else{
            var cl = '#0866c6';//blue
            if(dobj['service_status'] == 'present'){
                cl = '#fcb904';//yellow
            }
            else if(dobj['service_status'] == 'past'){
                cl = '#dd0000';//red
            }
        }

        event_data.push({
            title:dobj['name']+lbl,
            start: new Date(y, m, d),
            color:cl
        })
    }
</script>

<?php
    echo $this->Html->script('scripts/service_advisers/today_appointments.js');
?>